package n7.restaurant.java.Entity;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;

import n7.restaurant.java.Enum.Acces;

public class Porte {
	public static ArrayList<Porte> portes = new ArrayList<Porte>();

	private int x1;
	private int x2;
	private int y1;
	private int y2;
	private Vector<Acces> acces;

	public Porte() {
		super();
		this.acces = new Vector<Acces>();
	}

	public Porte(int x1, int x2, int y1, int y2) {
		super();
		this.x1 = x1;
		this.x2 = x2;
		this.y1 = y1;
		this.y2 = y2;
		this.acces = new Vector<Acces>();
	}

	public int getX1() {
		return x1;
	}

	public void setX1(int x1) {
		this.x1 = x1;
	}

	public int getX2() {
		return x2;
	}

	public void setX2(int x2) {
		this.x2 = x2;
	}

	public int getY1() {
		return y1;
	}

	public void setY1(int y1) {
		this.y1 = y1;
	}

	public int getY2() {
		return y2;
	}

	public void setY2(int y2) {
		this.y2 = y2;
	}

	public Vector<Acces> getAcces() {
		return acces;
	}

	public void setAcces(Vector<Acces> acces) {
		this.acces = acces;
	}

	public boolean addAcces(Acces acc) {
		return this.acces.add(acc);
	}

	public static Position getAccesPosition(Acces start, Acces finish) {
		for (Iterator<Porte> i = portes.iterator(); i.hasNext();) {
			Porte p = i.next();
			if (p.getAcces().contains(start) && p.getAcces().contains(finish)) {
				Position position  = new Position();
				position.setX((p.getX1()+p.getX2())/2);
				position.setY((p.getY1()+p.getY2())/2);
				position.setLieu(finish);
				return position;
			}
		}
		return null;
	}
}
